home *** CD-ROM | disk | FTP | other *** search
- /**********************************************************************
- * This file contains the bulf of the program. The functions which
- * are invloved in the changing of the creator and file types are in
- * this file.
- **********************************************************************/
-
- #include "Creator Changer.h"
- #include "Creator Changer.change.h"
-
-
-
- /**********************************************************************
- * Function Open_Changer_DLOG, this function gets the info from the
- * Changer Dialog box.
- **********************************************************************/
-
- void Open_Changer_DLOG(void)
- {
-
- Handle item_handle;
- short the_item;
- short item_type;
- Rect item_rect;
- Boolean done_with_dialog=FALSE;
- GrafPtr old_port;
-
- The_Dialog=GetNewDialog(CHNG_TYPE_DLOG_ID, NIL_PTR, IN_FRONT);
- ShowWindow(The_Dialog);
- GetPort(&old_port);
- SetPort(The_Dialog);
-
- while(!done_with_dialog)
- {
- Update_Change_Dialog();
- ModalDialog(NIL_PTR, &the_item);
- switch(the_item)
- {
- case CHNG_OK:
- // if the change is GOOD, then quit the dialog box
- done_with_dialog=Handle_OK_Change();
- break;
- case CHNG_CANCEL:
- done_with_dialog=TRUE;
- break;
- defualt:
- break;
- }
- }
-
- DisposDialog(The_Dialog);
- SetPort(old_port);
-
- }
-
-
-
- /**********************************************************************
- * Function Update_Change_Dialog, this function updates the change
- * dialog incase the dialog is covered by another window.
- **********************************************************************/
-
- void Update_Change_Dialog(void)
- {
-
- Handle handle;
- short diameter;
- short type;
- Rect rect;
-
- // Draw the current creator/file type text boxes
- Draw_Dialog();
-
- // Put a border around the OK button
- GetDItem(The_Dialog, CHNG_OK, &type, &handle, &rect);
- diameter=(rect.bottom-rect.top)/2+6;
- if(diameter<16) diameter=16;
- PenSize(3, 3);
- InsetRect(&rect, -4, -4);
- FrameRoundRect(&rect, diameter, diameter);
-
- }
-
-
-
- /**********************************************************************
- * Function Draw_Dialog, this function draws the objects in the
- * main dialog box.
- **********************************************************************/
-
- void Draw_Dialog(void)
- {
-
- Rect the_rect;
- File_Union temp, type;
- int i;
-
- TextFont(systemFont);
- TextSize(12);
- TextFace(0);
- PenSize(1, 1);
- SetRect(&the_rect, 115, 55, 196, 77);
- FrameRect(&the_rect);
- SetRect(&the_rect, 236, 55, 317, 77);
- FrameRect(&the_rect);
-
- type.TEXT[0]=TYPE_LEN;
-
- MoveTo(119, 70);
-
- // This is where I convert the types from an int to a char:
- // • First, I Make a file union with an unsigned int and a char string
- // • Then, I make a temp variable, where the unsinged int is assigned the type
- // • Next, I use a loop to copy the temp.TEXT to the variable type.TEXT, offset by one
- // • Last, I draw the type.TEXT string
- temp.LONG=File_Info.fdCreator;
- for(i=0;i<=TYPE_LEN;i++) type.TEXT[i+1]=temp.TEXT[i];
- DrawString(type.TEXT);
-
- MoveTo(240, 70);
- temp.LONG=File_Info.fdType;
- for(i=0;i<=TYPE_LEN;i++) type.TEXT[i+1]=temp.TEXT[i];
- DrawString(type.TEXT);
-
- }
-
-
-
- /**********************************************************************
- * Function Handle_OK_Change, this function calls the functions
- * which do the changing of the creator and file types. However,
- * if there is no information entered in the text fields the function
- * will alert the user.
- **********************************************************************/
-
- int Handle_OK_Change(void)
- {
-
- // Check to see if there is good data in the edit fields ...
- if(Check_Type_Data(CHNG_FILE) && Check_Type_Data(CHNG_CREATOR))
- {
- File_Info.fdType=Set_Type(CHNG_FILE);
- File_Info.fdCreator=Set_Type(CHNG_CREATOR);
-
- // Set the new creator and file types
- SetFInfo(File_Name, V_Ref_Num, &File_Info);
-
- // We sucessfully completed our mission !!
- return(GOOD);
- }
-
- // ... if not, the change was BAD.
- else
- {
- PREV_ALERT=FALSE; // Reset the alert.
- return(BAD);
- }
- }
-
-
-
- /**********************************************************************
- * Function Set_File_Type, this function sets the file type of the
- * specified file. (converts a string in a edit field to an
- * unsigned decimal equivalent).
- **********************************************************************/
-
- OSType Set_Type(int ID)
- {
-
- File_Union file_type, temp;
- Handle item_handle;
- short item_type;
- Rect item_rect;
- int i;
-
- GetDItem(The_Dialog, ID, &item_type, &item_handle, &item_rect);
- GetIText(item_handle, temp.TEXT);
-
- // This is just the oposite as I did above:
- for(i=0;i<=TYPE_LEN;i++) file_type.TEXT[i]=temp.TEXT[i+1];
- return(file_type.LONG);
-
- }
-
-
-
- /**********************************************************************
- * Function Check_Type_Data, this function checks the type entered
- * by the user. If there are more than 4 charachters than there is
- * an error, and if there is no data entered in there is an error.
- **********************************************************************/
-
- int Check_Type_Data(int ID)
- {
-
- Str15 item_text; // Allow a buffer incase someone trys to type in ...
- Handle item_handle; // ... more than four characters.
- short item_type;
- Rect item_rect;
- short len;
-
- GetDItem(The_Dialog, ID, &item_type, &item_handle, &item_rect);
- GetIText(item_handle, item_text);
-
- // see if the length of the string is zero (no data) or if it too long (over 4)...
- // ... and see if the alert was given before (don't want to annoy the user).
- len=item_text[0];
- if(len!=TYPE_LEN && !PREV_ALERT)
- {
- ParamText("\pTypes must be four (4) characters long!","\p", "\p(Spaces included)", "\p");
- Alert(ERROR_ALERT, NIL_PTR);
- PREV_ALERT=TRUE; // The alert was signaled once. Don't need to alert ...
- return(BAD); // ... someone twice in a row!
- }
- else return(GOOD);
-
- }